from applications.extensions import db

from datetime import datetime


# class CustomerUser(db.Model):
#     """Basic user model"""
#     id = db.Column(db.Integer, primary_key=True)
#     username = db.Column(db.String(255), unique=True, nullable=False)
#     email = db.Column(db.String(255), unique=True, nullable=False)
#     phone = db.Column(db.String(255), unique=True, nullable=False)
#     app_id = db.Column(db.String(255), unique=True, nullable=False)
#     app_key = db.Column(db.String(255), unique=True, nullable=False)
#     amount = db.Column(db.BigInteger, comment="余额")
#     active = db.Column(db.Boolean, default=True)
#     create_time = db.Column(db.DateTime, default=datetime.now(), comment='创建时间')
#     update_time = db.Column(db.DateTime, default=datetime.now(), onupdate=datetime.now(), comment='更新时间')


class BaiDuShare(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    book_name = db.Column(db.Text(), comment="资源名字")
    share_link = db.Column(db.Text(), comment="分享链接")
    share_pwd = db.Column(db.Text(), comment="分享链接密码")
    tag = db.Column(db.Text(), comment="标签")
    zip_code = db.Column(db.Text(), comment="获取资源的字符串")
    zip_password = db.Column(db.Text(), comment="资源解压的字符串")
    create_time = db.Column(db.DateTime, default=datetime.now(), comment='创建时间')
    update_time = db.Column(db.DateTime, default=datetime.now(), onupdate=datetime.now(), comment='更新时间')


class IdCardTable(db.Model):
    """Basic user model"""
    __tablename__ = 'id_card_table'
    __table_args__ = {'comment': '身份证'}

    id = db.Column(db.Integer, primary_key=True)
    md5_text = db.Column(db.String(255), unique=True, nullable=False, comment="图片md5值")
    request_result = db.Column(db.Text(), unique=True, comment="百度请求结果")
    create_time = db.Column(db.DateTime, default=datetime.now(), comment='创建时间')
    update_time = db.Column(db.DateTime, default=datetime.now(), onupdate=datetime.now(), comment='更新时间')

    def to_dict(self):
        return {
            "id": self.id,
            "request_result": self.request_result,
            "md5_text": self.md5_text,
        }


class TbPhoneSegmentInfo(db.Model):
    __tablename__ = 'tb_phone_segment'
    id = db.Column(db.Integer, primary_key=True)
    code = db.Column(db.String(255), comment="代码")
    section = db.Column(db.String(255), comment="号段")
    provincial_area = db.Column(db.String(255), comment="省区")
    city = db.Column(db.String(255), comment="城市")
    service_provider = db.Column(db.String(255), comment="服务商")
    area_code = db.Column(db.String(255), comment="区号")
    postal_Code = db.Column(db.String(255), comment="邮编")
    division_code = db.Column(db.String(255), comment="区划代码")

    def to_dict(self):
        return {c.name: getattr(self, c.name, None) for c in self.__table__.columns}


class OkDataLevel3(db.Model):
    __tablename__ = 'ok_data_level3'
    id = db.Column(db.Integer, primary_key=True, comment="主键")
    pid = db.Column(db.String(255), comment="父id")
    deep = db.Column(db.String(255), comment="深度")
    name = db.Column(db.String(255), comment="名字")
    pinyin_prefix = db.Column(db.String(255), comment="城市拼音前缀")
    pinyin = db.Column(db.String(255), comment="城市拼音")
    ext_id = db.Column(db.String(255), comment="行政代号")
    ext_name = db.Column(db.String(255), comment="行政代号名字")

    def to_dict(self):
        return {c.name: getattr(self, c.name, None) for c in self.__table__.columns}


class OkDataLevel4(db.Model):
    __tablename__ = 'ok_data_level4'
    id = db.Column(db.Integer, primary_key=True, comment="主键")
    pid = db.Column(db.String(255), comment="父id")
    deep = db.Column(db.String(255), comment="深度")
    name = db.Column(db.String(255), comment="名字")
    pinyin_prefix = db.Column(db.String(255), comment="城市拼音前缀")
    pinyin = db.Column(db.String(255), comment="城市拼音")
    ext_id = db.Column(db.String(255), comment="行政代号")
    ext_name = db.Column(db.String(255), comment="行政代号名字")

    def to_dict(self):
        return {c.name: getattr(self, c.name, None) for c in self.__table__.columns}


class OkGeo(db.Model):
    __tablename__ = 'ok_geo'
    id = db.Column(db.Integer, primary_key=True, comment="主键")
    pid = db.Column(db.String(255), comment="父id")
    deep = db.Column(db.String(255), comment="深度")
    name = db.Column(db.String(255), comment="名字")
    ext_path = db.Column(db.String(255), comment="")
    geo = db.Column(db.String(255), comment="中心坐标")
    polygon = db.Column(db.Text(), comment="范围坐标")
